package com.steven.ourcontest.main.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.steven.ourcontest.R
import com.steven.ourcontest.app.AppRouter
import com.steven.ourcontest.main.bean.RecruitTeam
import com.steven.ourcontest.team.bean.TeamAndLeader
import com.steven.ourcontest.team.bean.TeamInfo
import com.steven.ourcontest.team.bean.TeamInfoRes
import com.steven.ourcontest.utils.DateUtil

class RecruitTeamAdapter(private val context: Context) : RecyclerView.Adapter<ViewHolder>() {

    private val dataList by lazy {
        arrayListOf<TeamInfo>()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater = LayoutInflater.from(context).inflate(R.layout.item_recruit, parent, false)
        return ViewHolder(inflater)
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val itemData = dataList[position]
        holder.apply {
            tv_project_name?.text = itemData.teamName
            tv_match_name?.text = itemData.matchName
            tv_date?.text = DateUtil.timeStamp2Date(itemData.createTime, "yyyy-MM-dd")
            tv_member?.text = "${itemData.memberNum}人为该团队成员"
            itemView.setOnClickListener {
                AppRouter.openTeamDetailActivity(context, itemData.id)
            }
        }
    }

    fun submitData(data: List<TeamInfo>) {
        dataList.addAll(data)
        notifyDataSetChanged()
    }
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val tv_project_name: TextView? = itemView.findViewById(R.id.tv_project_name)
    var tv_match_name: TextView? = itemView.findViewById(R.id.tv_match_name)
    var tv_date: TextView? = itemView.findViewById(R.id.tv_date)
    var tv_member: TextView? = itemView.findViewById(R.id.tv_member)
}